package cn.com.darly.videoandroidpm.ui.adapter;

import android.content.Context;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.darly.common.ParentAdapter;
import com.darly.dview.widget.camera.util.ImageLoaderUtil;

import java.util.List;

import cn.com.darly.videoandroidpm.R;
import cn.com.darly.videoandroidpm.bean.FragmentMainInfo;
import cn.com.darly.videoandroidpm.common.HTMLImageGetter;

/** 带标签的ListView适配器
 * @author Darly/张宇辉/2018/5/7 11:29
 * @version 1.0/cn.com.darly.videoandroidpm.ui.adapter
 */
public class PublishedAmuseAdapter extends ParentAdapter<FragmentMainInfo> {


    public PublishedAmuseAdapter(List<FragmentMainInfo> data, int resID, Context context) {
        super(data, resID, context);
    }

    @Override
    public View HockView(int position, View view, ViewGroup parent, int resID, final Context context, FragmentMainInfo info) {
        UserHolder holder = null;
        if (view == null){
            view = LayoutInflater.from(context).inflate(resID,null);
            holder = new UserHolder();
            holder.usericon = view.findViewById(R.id.id_item_fragment_main_author_icon);
            holder.username = view.findViewById(R.id.id_item_fragment_main_author_name);
            holder.time = view.findViewById(R.id.id_item_fragment_main_author_time);
            holder.status = view.findViewById(R.id.id_item_fragment_main_status);
            holder.title = view.findViewById(R.id.id_item_fragment_main_title);
            holder.content = view.findViewById(R.id.id_item_fragment_main_content);
            holder.desc = view.findViewById(R.id.id_item_fragment_main_desc);
            holder.like = view.findViewById(R.id.id_item_fragment_main_like);
            view.setTag(holder);
        }else {
            holder = (UserHolder) view.getTag();
        }

        if (info != null) {
            ImageLoaderUtil.getInstance().loadImage("",holder.usericon);
            holder.username.setText(info.getUser().getName());
            holder.time.setText(info.getUpdatetime());
            switch (info.getStatus()){
                case 0:
                    holder.status.setText("审核中");
                    holder.status.setBackgroundResource(R.drawable.amuse_status_applicate);
                    break;
                case 1:
                    holder.status.setText("已发布");
                    holder.status.setBackgroundResource(R.drawable.amuse_status_publish);
                    break;
                case 2:
                    holder.status.setText("已驳回");
                    holder.status.setBackgroundResource(R.drawable.amuse_status_abord);
                    break;
            }


            holder.title.setText(info.getTitle());
            holder.content.setText(Html.fromHtml(info.getContent(),new HTMLImageGetter(context,holder.content),null));
            holder.desc.setText("浏览"+info.getWatch()+"---评论"+info.getComment());
            holder.like.setVisibility(View.GONE);

        }
        return view;
    }

    class UserHolder{
        ImageView usericon;
        TextView username;
        TextView time;
        TextView status;
        TextView title;
        TextView content;
        TextView desc;
        ImageView like;
    }

}